package com.nexus.all.manager;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.all.dao.NoteLikeViewMapper;
import com.nexus.all.model.NoteLikeView;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NoteLikeViewManager extends ServiceImpl<NoteLikeViewMapper, NoteLikeView> {

    /**
     * 批量获取笔记/评论点赞数量
     *
     * @param noteIds
     * @param noteLikeType
     * @return
     */
    public List<NoteLikeView> getByLikeDataIds(List<Long> noteIds, Byte noteLikeType) {
        LambdaQueryWrapper<NoteLikeView> wrapper = NoteLikeView.gw();
        wrapper.eq(NoteLikeView::getNoteLikeType, noteLikeType);
        wrapper.in(NoteLikeView::getLikeDataId, noteIds);
        return list(wrapper);
    }

    /**
     * 获取笔记/评论点赞数量
     *
     * @param noteId
     * @param noteLikeType
     * @return
     */
    public NoteLikeView getByLikeDataId(Long noteId, Byte noteLikeType) {
        LambdaQueryWrapper<NoteLikeView> wrapper = NoteLikeView.gw();
        wrapper.eq(NoteLikeView::getNoteLikeType, noteLikeType);
        wrapper.eq(NoteLikeView::getLikeDataId, noteId);
        return getOne(wrapper);
    }
}
